import 'package:flutter/material.dart';
import 'package:flutter_yishop/pages/address/AddressAdd.dart';
import 'package:flutter_yishop/pages/address/AddressEdit.dart';
import 'package:flutter_yishop/pages/address/AddressList.dart';
import 'package:flutter_yishop/pages/checkout/CheckOutPage.dart';
import 'package:flutter_yishop/pages/home/BannerPage.dart';
import 'package:flutter_yishop/pages/login/Login.dart';
import 'package:flutter_yishop/pages/order/OrderInfoPage.dart';
import 'package:flutter_yishop/pages/order/OrderPage.dart';
import 'package:flutter_yishop/pages/pay/PayPage.dart';
import 'package:flutter_yishop/pages/product/ProductList.dart';
import 'package:flutter_yishop/pages/product/product_content/ProductContent.dart';
import 'package:flutter_yishop/pages/register/Register.dart';
import 'package:flutter_yishop/pages/shopcar/ShopCar.dart';
import 'package:flutter_yishop/pages/splash/Splash.dart';
import 'package:flutter_yishop/provider/CheckOut.dart';
import '../constants/Constants.dart';
import '../pages/tabs/Tabs.dart';
import '../pages/search/Search.dart';
// import '../pages/product/Product.dart';
import '../pages/product/ProductSecond.dart';

//配置路由
final routes = {
  Constants.TABS: (context) => Tabs(),
  Constants.SEARCH: (context) => Search(),
  Constants.PRODUCT: (context,{arguments}) => Product(arguments:arguments),
  // Constants.PRODUCT: (context,{arguments}) => ProductListPage(arguments:arguments),
  Constants.PRODUCTCONTENT: (context,{arguments}) => ProductContentPage(arguments:arguments),
  Constants.BANNER: (context,{arguments}) => BannerPage(arguments:arguments),
  Constants.SHOPCART: (context) => ShopCar(),
  Constants.LOGIN:(context) => LoginPage(),
  Constants.REGISTER: (context) => RegisterPage(),
  Constants.SPLASH: (context) => SplashPage(),
  Constants.CHECKOUT: (context,{arguments}) => CheckOutPage(arguments:arguments),
  Constants.ADDRESSADD: (context) => AddressAdd(),
  Constants.ADDRESSLIST: (context) => AddressList(),
  Constants.ADDRESSEDIT: (context,{arguments}) => AddressEditPage(arguments:arguments),
  Constants.PAY: (context) => PayPage(),
  Constants.ORDER: (context) => OrderPage(),
  Constants.ORDERINFO: (context,{arguments}) => OrderInfoPage(arguments:arguments),
};

//固定写法
var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  final String name = settings.name;
  final Function pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};
